package com.erp.framework.util;

import com.erp.app.common.ProjectConstants;
import com.erp.app.common.select.beans.SelectDelegate;
import com.erp.framework.SimpleConstants;

public class EjbUtil implements SimpleConstants{

    public static String getAppropriateCompanyCode(String loginCompCode, String shareId) {

        if (CommonUtil.isEmpty(loginCompCode) || CommonUtil.isEmpty(shareId))
            return "";

        SelectDelegate dg = new SelectDelegate();
        String table = "T_SYS_PARAM";
        String column = "PARAM_VAL";
        String where = "PARAM_ID = '" + shareId + "'";
        String shareCompCode = (String) dg.findField(table, column, where);

        table = "T_SYS_PARAM";
        column = "DECODE('" + shareCompCode + "', '1', PARAM_VAL, '" + loginCompCode + "')";
        where = "PARAM_ID = '" + ProjectConstants.SP_GENERAL_COMPANY_CODE + "'";
        String rslt = (String) dg.findField(table, column, where);

        return rslt;
    }

    public static String getField(String table, String column, String where) {
        String result = null;

        SelectDelegate sdg = new SelectDelegate();
        Object obj = sdg.findField(table, column, where);
        if ((obj != null) && (!"".equals(obj.toString()))) {
            result = obj.toString();
        }
        return result;
    }

}
